package com.zmj.sy.mom.srv.aps.service;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zmj.sy.mom.srv.aps.bean.entity.resource.Station;
import com.zmj.sy.mom.srv.aps.bean.vo.stationbatch.StationBatchEmployeeGroupReqVo;
import com.zmj.sy.mom.srv.aps.bean.vo.stationbatch.StationBatchSchemeReqVo;
import com.zmj.sy.mom.srv.aps.bean.vo.stationbatch.StationBatchWorkTemplateReqVo;
import com.zmj.sy.mom.srv.aps.mapper.*;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@RequiredArgsConstructor
@Service
public class StationBatchService {
    private final StationMapper stationMapper;

    private final WeekdaySchemeMapper weekdaySchemeMapper;

    private final WeekdayRuleMapper weekdayRuleMapper;

    private final StationWeekdaySchemeMapper stationWeekdaySchemeMapper;

    private final StationWeekdayRuleMapper stationWeekdayRuleMapper;

    @Transactional
    public void scheme(StationBatchSchemeReqVo reqVo) {

        List<Station> stationList = stationMapper.selectBatchIds(reqVo.getStationIds());

        for (Station station : stationList) {
            Station s = new Station();
            s.setId(station.getId());
            s.setShiftTypeId(reqVo.getSchemeId());
            stationMapper.updateById(s);
        }

    }



    @Transactional
    public void workTemplate(StationBatchWorkTemplateReqVo reqVo) {

        LambdaUpdateWrapper<Station> updateWrapper = Wrappers.<Station>lambdaUpdate();
        updateWrapper.set(Station::getWorkTemplateId, reqVo.getWorkTemplateId());
        updateWrapper.in(Station::getId, reqVo.getStationIds());
        stationMapper.update(null, updateWrapper);

    }

    @Transactional
    public void employeeGroup(StationBatchEmployeeGroupReqVo reqVo) {
        LambdaUpdateWrapper<Station> updateWrapper = Wrappers.<Station>lambdaUpdate();
        updateWrapper.set(Station::getEmployeeId, reqVo.getEmployeeGroupId());
        updateWrapper.in(Station::getId, reqVo.getStationIds());
        stationMapper.update(null, updateWrapper);
    }
}
